package com.hyh.user.service.impl;

import cn.hutool.http.HttpStatus;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hyh.user.dao.AddressMapper;
import com.hyh.user.domain.Address;
import com.hyh.user.result.PageResult;
import com.hyh.user.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressMapper addressMapper  ;

    // 添加地址
    @Override
    public PageResult addAddress(Address address) {
        int insert = addressMapper.insert(address);
        if(insert == 0)
            return new PageResult(HttpStatus.HTTP_INTERNAL_ERROR, null,"添加失败");
        return new PageResult(HttpStatus.HTTP_OK,null,"添加成功");
    }

    // 查询地址
    @Override
    public PageResult selectListAddress(Long userId) {
        LambdaQueryWrapper<Address> qw = new LambdaQueryWrapper<>();
        qw.eq(Address::getUserId,userId);
        return new PageResult(HttpStatus.HTTP_OK,addressMapper.selectList(qw),"查询成功");
    }
}
